home *** CD-ROM | disk | FTP | other *** search
- /* NAME:
- ES Handler.c
-
- WRITTEN BY:
- Dair Grant
-
- DESCRIPTION:
- This file contains an ES Handler for use by Extension Shell.
-
- ___________________________________________________________________________
- */
- //=============================================================================
- // Include files
- //-----------------------------------------------------------------------------
- #include <Resources.h>
- #include <Gestalt.h>
- #include <Traps.h>
- #include "A4Stuff.h"
- #include "SetupA4.h"
- #include "ES.h"
- #include "ICeTEe AddrsTable.h"
- #include "ICeTEe Constants.h"
- #include "ES Handler.h"
-
-
- //=============================================================================
- // Private types
- //-----------------------------------------------------------------------------
- typedef struct {
- AEEventClass evClass;
- AEEventID evID;
- } BkEventRec, **BkEventHandle;
-
-
- //=============================================================================
- // Private function prototypes
- //-----------------------------------------------------------------------------
- void main(short theMsg, ESParamBlock *theParamBlock);
- void InitialiseParamBlock(void);
- void InitialiseAddrsTable(void);
- void HandleTheError(void);
- void SetUpIcons(short animDelay, short numIcons, short firstIcon);
-
-
- //=============================================================================
- // Global variables
- //-----------------------------------------------------------------------------
- ESParamBlock *gTheParamBlock;
-
-
- //=============================================================================
- // main : Entry point to our code resource.
- //-----------------------------------------------------------------------------
- // Note : Extension Shell communicates with us via a message constant,
- // and a pointer to a structure it owns. Our job is to fill in
- // the details in that structure, depending on what it wants us
- // to do.
- //-----------------------------------------------------------------------------
- void main(short theMsg, ESParamBlock *theParamBlock)
- { long oldA4;
-
- // Set up A4 so that we can access our globals
- #ifndef powerc
- oldA4 = SetCurrentA4();
- #endif
-
- #if qDebug >= 3
- DebugStr("\pES Handler entered");
- #endif
-
- gTheParamBlock = theParamBlock;
-
-
- // Case out on what we have to do
- switch(theMsg) {
- case kInitialiseParamBlock:
- InitialiseParamBlock();
- break;
-
- case kInitialiseAddrsTable:
- InitialiseAddrsTable();
- break;
-
- case kHandleError:
- HandleTheError();
- break;
-
- default:
- ;
- }
-
- #if qDebug >= 3
- DebugStr("\pES Handler exit");
- #endif
-
- // Restore A4
- #ifndef powerc
- SetA4(oldA4);
- #endif
- }
-
-
- //=============================================================================
- // InitialiseParamBlock : Initialises the ParamBlock.
- //-----------------------------------------------------------------------------
- // Note : We have three tasks to perform.
- // • Check to see if we can run
- // • Set up the icons we want to display
- // • Set up the code we want installed
- //-----------------------------------------------------------------------------
- void InitialiseParamBlock(void)
- {
- long response;
-
- #if qDebug >= 3
- DebugStr("\pInitialiseParamBlock entered");
- #endif
-
- // Check for System 7. We depend on having System 7, and won't
- // run if we don't have it. If we don't have it, we beep, post
- // an error message, and show our disabled icon(s).
- if (gTheParamBlock->systemVersion < 0x0700)
- {
- // Error details
- gTheParamBlock->beepNow = true;
- gTheParamBlock->postError = true;
- gTheParamBlock->errorStringsID = kErrorStrings;
- gTheParamBlock->errorStringIndex = kNeedSystemSeven;
-
-
- // Icon details
- SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
- }
-
- // Check for Component Manager
- if ( Gestalt(gestaltComponentMgr, &response) != noErr)
- {
- // Error details
- gTheParamBlock->beepNow = true;
- gTheParamBlock->postError = true;
- gTheParamBlock->errorStringsID = kErrorStrings;
- gTheParamBlock->errorStringIndex = kNeedCompMgr;
-
-
- // Icon details
- SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
- }
-
-
- // If a shift key, or the mouse button, is down, we don't load either.
- // We don't post an error, but we do show our disabled icon(s) to let
- // the user know they've turned us off.
- else if ((*gTheParamBlock->IsKeyMouseDown)(kShiftKey, true))
- {
- // Icon details
- SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
- }
-
-
-
- // Otherwise, we're allowed to run. If we had a Control Panel, we
- // would also check to see if our Control Panel had turned us
- // off (by setting some preference resource).
- else
- {
- // Icon details
- SetUpIcons(kEnabledAnimDelay, kMyNumEnabledIcons, kMyFirstEnabledIcon);
-
-
- // We install one trap patch, one code block, and request an address table
- gTheParamBlock->installAddressTable = true;
- gTheParamBlock->addressTableSelector = kICeTEeAddressTable;
- gTheParamBlock->numCodeResources = 1;
-
-
- // Details for a trap patch to MenuSelect()
- gTheParamBlock->theCodeResources[kTEClick].resType = kICeTEeResType;
- gTheParamBlock->theCodeResources[kTEClick].resID = kICeTEeResID;
- gTheParamBlock->theCodeResources[kTEClick].codeType = kTrapPatchType;
- gTheParamBlock->theCodeResources[kTEClick].theCodeThing.theTrapPatch.trapWord = _TEClick;
- gTheParamBlock->theCodeResources[kTEClick].theCodeThing.theTrapPatch.globalpatch = true;
- }
-
- #if qDebug >= 3
- DebugStr("\pInitialiseParamBlock exit");
- #endif
- }
-
-
- //=============================================================================
- // InitialiseAddrsTable : Initialise the address table.
- //-----------------------------------------------------------------------------
- // Note : If we requested an address table, Extension Shell calls us back
- // to allow us to initialise any extensions we've made to it.
- //
- // This routine will only be called if we request an address
- // table, and is called after the address table is installed,
- // but before any of the items in gTheParamBlock->theCodeResources
- // are processed (since they might need to access the address
- // table).
- //
- // We should initialise the magicNumber and versionNumber fields
- // with constants fixed for this build. One possible number for the
- // magicNumber field would be sizeof() our address table structure.
- //-----------------------------------------------------------------------------
- void InitialiseAddrsTable(void)
- {
- ICeTEeAddressTable *theAddressTable;
- Handle exclusions;
- Handle errors;
- BkEventHandle bkEvent;
-
- #if qDebug >= 3
- DebugStr("\pInitialiseAddrsTable entered");
- #endif
-
- // Call Gestalt to find our address table
- Gestalt(kICeTEeAddressTable, (long *) &theAddressTable);
-
-
- // Initialise the magic number and version fields
- theAddressTable->magicNumber = kMyTableMagic;
- theAddressTable->versionNumber = kMyTableVersion;
-
-
-
- // Initialise our custom values
-
- // Bookmark event class & ID
- bkEvent = (BkEventHandle)Get1Resource(kBkEventResType, kBkEventResID);
-
- if (bkEvent != nil)
- {
- theAddressTable->bkEventClass = (**bkEvent).evClass;
- theAddressTable->bkEventID = (**bkEvent).evID;
- ReleaseResource((Handle)bkEvent);
-
- // Exclusions
- exclusions = Get1Resource(kExclusionsResType, kExclusionsResID);
- DetachResource(exclusions);
- theAddressTable->exclusions = exclusions;
-
- // Error strings
- errors = Get1Resource(kErrorsResType, kErrorsResID);
- DetachResource(errors);
- theAddressTable->errors = errors;
-
- }
- else
- {
- gTheParamBlock->beepNow = true;
- gTheParamBlock->postError = true;
- gTheParamBlock->errorStringsID = kErrorStrings;
- gTheParamBlock->errorStringIndex = kUnknownError;
- }
-
- #if qDebug >= 3
- DebugStr("\pInitialiseAddrsTable exit");
- #endif
- }
-
-
- //=============================================================================
- // HandleTheError : Handle any errors
- //-----------------------------------------------------------------------------
- // Note : This routine is called if an error occurred during the
- // installation of the items in gTheParamBlock->theCodeResources.
- //
- // If an error occurs we beep, post an error, and request that
- // as much as possible of our code be uninstalled. We also reset
- // the icon details to show our disabled icons.
- //-----------------------------------------------------------------------------
- void HandleTheError(void)
- {
- #if qDebug >= 3
- DebugStr("\pHandleTheError entered");
- #endif
-
- // Decide how we want to handle the error
- gTheParamBlock->removeInstalledCode = true;
- gTheParamBlock->beepNow = true;
- gTheParamBlock->postError = true;
- gTheParamBlock->errorStringsID = kErrorStrings;
-
-
- // Message to display to the user
- gTheParamBlock->errorStringIndex = kUnknownError;
-
-
- // Icon details
- SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
-
- #if qDebug >= 3
- DebugStr("\pHandleTheError exit");
- #endif
- }
-
-
- //=============================================================================
- // SetUpIcons : Set up our the icon fields in gTheParamBlock.
- //-----------------------------------------------------------------------------
- // Note : We are passed in the resource ID of the first icon, the number
- // of icons, and a delay for animation. We fill these details
- // in to gTheParamBlock.
- //-----------------------------------------------------------------------------
- void SetUpIcons(short animDelay, short numIcons, short firstIcon)
- {
- short i;
-
- #if qDebug >= 3
- DebugStr("\pSetUpIcons entered");
- #endif
-
- gTheParamBlock->animationDelay = animDelay;
- gTheParamBlock->numIcons = numIcons;
- for (i = 1; i <= numIcons; i++)
- gTheParamBlock->theIcons[i] = firstIcon + i - 1;
-
- #if qDebug >= 3
- DebugStr("\pSetUpIcons exit");
- #endif
- }
-